package com.sinosoft.utils;

import java.util.Arrays;

/**
 * 四级地址@@@@格式截取方法，兼容中间空缺
 * @Author: WangShengJie
 * @Date: 2025/3/12
 */
public class MainDemo {
    public static void main(String[] args) {
//        String str = "210000@210200@210202@210202011@";
//        String[] split = str.split("@");
//        System.out.println(split.length);
//        System.out.println(Arrays.toString(split));

        String str = "210000@210200@210202@210202011@反恐打击非法·";
//        String[] split1 = add.split("@");
//        System.out.println(split1.length);
//        System.out.println(Arrays.toString(split1));
//
//        //
////        int i = str.indexOf("@");
//        StringBuffer sb = new StringBuffer(str);
//        String substring = sb.substring(0, i);
//        System.out.println(substring);
//        str.replaceFirst(substring+"@","");
        String province = "";
        String city = "";
        String country = "";
        String town = "";
        int i = 1;
        while (!(str.indexOf("@") < 0)) {
            String address = str.substring(0, str.indexOf("@"));
            str=str.replaceFirst(address + "@", "");
            System.out.println(str);
            if (i == 1) {
                province = address;
                // 一级
                System.out.println("*"+province);
            } else if (i == 2) {
                // 二级
                city = address;
                System.out.println("**"+city);
            } else if (i == 3) {
                // 三级
                country = address;
                System.out.println("***"+country);
            } else if (i == 4) {
                // 四级
                town = address;
                System.out.println("****"+town);
            }
            i++;
            System.out.println(i);

        }
        System.out.println(str);
    }
}
